package com.zone.vehicle.superApps.model;

import android.content.Context;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.zone.sdk.module.appstore.entity.AppEntity;
import com.zone.vehicle.superApps.enums.AppTypeEnum;
import com.zone.vehicle.superApps.repository.AppManagerRepository;

import java.util.List;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper=false)
public class AppManagerViewModel extends ViewModel {

    private static final String TAG = AppManagerViewModel.class.getSimpleName();

    private MutableLiveData<List<AppEntity>> activityApp = new MutableLiveData<>();

    private MutableLiveData<List<AppEntity>> installedApp = new MutableLiveData<>();

    private MutableLiveData<List<AppEntity>> activityLightApp = new MutableLiveData<>();
    private MutableLiveData<List<AppEntity>> installedLightApp = new MutableLiveData<>();

    private MutableLiveData<List<AppEntity>> needUpdateApp = new MutableLiveData<>();

    private AppManagerRepository repository;

    public AppManagerViewModel(AppManagerRepository repository){
        this.repository = repository;
    }

    public MutableLiveData<List<AppEntity>> getActivityApp() {
        return activityApp;
    }

    public MutableLiveData<List<AppEntity>> getInstalledApp() {
        return installedApp;
    }

    public MutableLiveData<List<AppEntity>> getActivityLightApp() {
        return activityLightApp;
    }

    public MutableLiveData<List<AppEntity>> getInstalledLightApp() {
        return installedLightApp;
    }

    public MutableLiveData<List<AppEntity>> getNeedUpdateApp() {
        return needUpdateApp;
    }

    /**
     * 获取操作中APP：下载、安装
     * @param type
     */
    public void getActivityApp(AppTypeEnum type){
        List<AppEntity> appEntityList = repository.getActivityApp(type);
        if (type == AppTypeEnum.APP){
            activityApp.setValue(appEntityList);
        }else if (type == AppTypeEnum.APP_LIGHT){
            activityLightApp.setValue(appEntityList);
        }
    }

    public void getNeedUpdateAppData(){

    }

    /**
     * 获取已安装APP
     * @param type
     */
    public void getInstalledApp(AppTypeEnum type){
        List<AppEntity> appEntityList = repository.getInstalledApp(type);
        if (type == AppTypeEnum.APP){
            installedApp.setValue(appEntityList);
        }else if (type == AppTypeEnum.APP_LIGHT){
            installedLightApp.setValue(appEntityList);
        }
    }

    /**
     * 快应用下载
     * @param appEntity
     */
    public void downLoadApp(Context context, int action, AppEntity appEntity){
        repository.downLoadApp(context, action, appEntity);
    }

    /**
     * 快应用下载
     * @param appEntity
     */
    public void downLoadLightApp(AppEntity appEntity){

    }

}